//
//  Food_classroomVC.m
//  Hand-held_kitchen
//
//  Created by dllo on 16/1/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Food_classroomVC.h"
#import <AFNetworking.h>
#import "ShiKeCell.h"
#import "ShiKeModel.h"
#import <UIImageView+WebCache.h>
#import "SKErJiVc.h"
#import "lunbo.h"
@interface Food_classroomVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *dataArr;//下面数组
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSMutableArray *lunboArr; // 轮播图数组
@end

@implementation Food_classroomVC
- (void)dealloc
{
    [_dataArr release];
    [_tableView release];
    [_lunboArr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title= @"食客";
    [self data];
    [self table];
    
    
    
    
}










// tableView
-(void)table
{
    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    _tableView.dataSource = self;
    _tableView.delegate =self;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[ShiKeCell class] forCellReuseIdentifier:@"cell"];
    
    [_tableView release];
}
//  数据
-(void)data
{
    NSString *str = @"http://api.izhangchu.com/?size=20&page=1&methodName=CourseIndex&version=4.3&";
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:str parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"成功:%@", responseObject);
        NSArray *arr = responseObject[@"data"][@"data"];
  /**<  下面的Cell数组 */
        self.dataArr = [ShiKeModel modelHanderWithArray:arr];
        /**<  轮播图数组 */
        NSArray *arr1 = responseObject[@"data"][@"top"];
        self.lunboArr = [ShiKeModel modelHanderWithArray:arr1];
        NSMutableArray *aaarr = [NSMutableArray array];
        for (ShiKeModel *m in _lunboArr) {
            NSString *str = m.banner_picture;
            [aaarr addObject:str];
        }
        /**<  轮播图 */
        lunbo *b = [[lunbo alloc] initWithFrame:CGRectMake(0, 0, 375 * KUAN, 190 * GAO) stringArray:aaarr];
        _tableView.tableHeaderView = b;
        [_tableView reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}


// cell 个数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _dataArr.count;
    
}
//cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShiKeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    ShiKeModel *m =_dataArr[indexPath.row];
    // 取后面的字符串
    NSString *string8 = [m.series_name substringFromIndex:1];
    // 切分字符串
    NSArray *arr = [string8 componentsSeparatedByString:@"#"];
  
   cell.wenzi.text = [NSString stringWithFormat:@"%@\n\n%@  %@/%@集  %@人做过",arr[1],arr[0],[m.episode stringValue],[m.episode_sum stringValue],[m.play stringValue] ];
    
    // 图片
    [cell.tupian sd_setImageWithURL:[NSURL URLWithString:m.image]];

    return cell;
    
}
// cell 高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200 * GAO;
}

/**<  点击方法 */
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShiKeModel *m =_dataArr[indexPath.row];
    SKErJiVc *dierye = [[SKErJiVc alloc]init];
    /**<  属性传值 穿个id和title */
    dierye.Iddddd =[m.series_id stringValue];
    dierye.title = m.series_name;
    
    [self.navigationController pushViewController:dierye animated:YES];
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
